package com.hc.mybatis.generator.plugins;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Interface;
import org.mybatis.generator.api.dom.java.TopLevelClass;

import java.util.List;

/**
 * @Description: 加@Component
 * @author: hc
 * @version: v1.0
 * @create at: 2020/7/15 20:48
 * @reviewer:
 * @review at:
 *
 * Revision history:
 * date             author      version     content
 * ------------------------------------------------------------
 * 2020/7/15           hc          v1.0        XXXX
 */
public class MapperAnnotationPlugin extends PluginAdapter {

    public MapperAnnotationPlugin() {
    }

    @Override
    public boolean validate(List<String> warnings) {
        return true;
    }

    @Override
    public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
        if (introspectedTable.getTargetRuntime() == IntrospectedTable.TargetRuntime.MYBATIS3) {
            interfaze.addImportedType(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Mapper"));
            interfaze.addAnnotation("@Mapper");
        }
        return true;
    }

}
